/* The link = http://poj.org/problem?id=1057
 * Sorry for adding two WAs for not understanding the meaning of the problems
 */

#include <iostream>
#include <string>
//#include <map>
#include <vector>
#include <algorithm>

using namespace std;

// Name structure
typedef struct ItemName {
	string name;
	vector<struct ItemName*> fileChildren;
	vector<struct ItemName*> directoryChidren;
	struct ItemName* parent;
	ItemName();
	ItemName(string nm);
} Item, *pItem;

Item::ItemName()
{
}

Item::ItemName(string nm)
{
	name = nm;
}



bool itemComparison(pItem i1, pItem i2)
{
	if (strcmp(i1->name.c_str(), i2->name.c_str()) >= 0)
		return true;
	return false;
}

bool fileItemComparison(pItem i1, pItem i2)
{
	//int length = i1->name.length() < i2->name.length() ? i1->name.length() : i2->name.length();
	//for (int i = 0; i < length; i++) {
	//	if (!isdigit(i1->name[i])) {
	//		if (i1->name[i] < i2->name[i]) {
	//			return false;
	//		} else if (i1->name[i] > i2->name[i]) {
	//			return true;
	//		}
	//	} else {
	//		if (i1->name[i] < i2->name[i]) {
	//			return true;
	//		} else if (i1->name[i] > i2->name[i]) {
	//			return false;
	//		}
	//	}
	//}

	//if (i1->name.length() > length) {
	//	return true;
	//}
	//return false;
	return i1->name < i2->name;
}

// Store the file structure as a map
//typedef pair<string, string> string_pair;
//typedef pair<Item, string> item_string;
//map<Item, string> fileSystem;

void printfFileSystem(int level, pItem currentItemPointer)
{
	cout << currentItemPointer->name << endl;
	if (!currentItemPointer->directoryChidren.empty()) {
		//sort(currentItemPointer->directoryChidren.begin(), currentItemPointer->directoryChidren.end(), itemComparison);
		/*vector<pItem>::iterator iter = currentItemPointer->directoryChidren.begin();*/
		for (int i = 0; i < currentItemPointer->directoryChidren.size(); i++) {
		//while (iter != currentItemPointer->directoryChidren.end()) {
			for (int j = 0; j < level; j++) {
				cout << "|     ";
			}
			
			printfFileSystem(level + 1, currentItemPointer->directoryChidren[i]);
			//++iter;
		}
	}

	if (!currentItemPointer->fileChildren.empty()) {
		sort(currentItemPointer->fileChildren.begin(), currentItemPointer->fileChildren.end(), fileItemComparison);
		vector<pItem>::iterator iter = currentItemPointer->fileChildren.begin();
		while (iter != currentItemPointer->fileChildren.end()) {
			if (level > 1) {
				for (int i = 0; i < level - 1; i++) {
					cout << "|     ";
				}
			}

			printfFileSystem(level + 1, *iter);
			++iter;
		}
	}
}

int main(int argc, char *argv[])
{
	string name;
	int dataSet = 1;
	pItem currentRoot;
	pItem currentDirectoryPointer;
	while (cin >> name && name != "#") {
		currentRoot = new Item("ROOT");
		currentDirectoryPointer = currentRoot;
		// One data set begin
		while (name != "*") {
			if (name[0] == 'f') {
				// Means a file name
				pItem pItemName = new Item(name);
				pItemName->parent = currentDirectoryPointer;
				currentDirectoryPointer->fileChildren.push_back(pItemName);
			} else if (name[0] == 'd') {
				// Means a directory name
				pItem pItemName = new Item(name);
				pItemName->parent = currentDirectoryPointer;
				currentDirectoryPointer->directoryChidren.push_back(pItemName);
				currentDirectoryPointer = pItemName;
			} else if (name[0] == ']') {
				// A directory ends
				currentDirectoryPointer = currentDirectoryPointer->parent;
			}
			cin >> name;
		}

		// Show the data structure
		printf("DATA SET %d:\n", dataSet);
		int level = 1;
		printfFileSystem(level, currentRoot);
		cout << endl;

		++dataSet;
	}
	return 0;
}